<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" ref="dataFormRef" @keyup.enter.native="getDataList()">
      <el-form-item>
        退货日期：
        <el-date-picker v-model="dataForm.queryDates" type="daterange" value-format="yyyy-MM-dd" range-separator="至"
          start-placeholder="开始日期" end-placeholder="结束日期" size="mini" @blur="getDataList()" clearable>
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        审批状态：
        <el-select size="mini" v-model="dataForm.auditStatus" clearable placeholder="请选择" @change="getDataList()"
          @clear="getDataList()">
          <el-option value="1" label="审批通过"></el-option>
          <el-option value="0" label="未审批"></el-option>
          <el-option value="-1" label="不通过"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        主单过滤：
        <el-select size="mini" v-model="dataForm.queryField" clearable placeholder="请选择" @change="getDataList()"
          @clear="getDataList()">
          <el-option v-for="item in queryFields" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input size="mini" v-model="dataForm.key" placeholder="参数名" clearable @blur="getDataList()"
          @clear="getDataList()"></el-input>
      </el-form-item>

      <el-form-item>
        明细过滤：
        <el-select size="mini" v-model="dataForm.queryItemField" clearable placeholder="请选择" @change="getDataList()"
          @clear="getDataList()">
          <el-option v-for="item in queryItemFields" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input size="mini" v-model="dataForm.itemKey" placeholder="参数名" clearable @blur="getDataList()"
          @clear="getDataList()"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button size="mini" type="success" @click="getDataList()" icon="el-icon-search">查询</el-button>
        <el-button @click="resetForm" size="mini" type="warning" icon="el-icon-refresh-left">重置</el-button>
      </el-form-item>
    </el-form>
    <el-form>
      <el-form-item>
        <el-button size="mini" v-if="isAuth('purchase:purchasesbackorder:save')" type="primary"
          @click="addOrUpdateHandle()" icon="el-icon-plus">新增</el-button>
        <el-button size="mini" v-if="isAuth('purchase:purchasesbackorder:delete')" type="danger" @click="deleteHandle()"
          icon="el-icon-delete" :disabled="dataListSelections.length <= 0">删除</el-button>
          <el-button size="mini" v-if="isAuth('purchase:purchasesbackorder:export')" type="primary" @click="exportData"
            class="iconfont icon-topsales">导出</el-button>
          <el-button size="mini" v-if="isAuth('purchase:purchasesbackorder:audit')" type="success" @click="showAuditDialog()"
            class="iconfont icon-shengyijing">审核
          </el-button>
        <!-- </el-button-group> -->
      </el-form-item>
    </el-form>
    <!-- 主表 -->
    <el-table :data="dataList" size="mini" v-loading="dataListLoading" @selection-change="selectionChangeHandle"
      style="width: 100%;" @cell-click="tableDbEdit" @cell-dblclick="tableDbEdit" height="320"
      :header-cell-style="{ background: '#fcfcfc', color: '#606266', height:'36px'}">
      <el-table-column type="selection" header-align="center" align="center" width="50">
      </el-table-column>
      <el-table-column prop="backNo" header-align="center" align="center" label="退货单号" width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-tag type="success" size="mini" @click="copyText(scope.row.backNo)" style="cursor: pointer;" >
            复制
          </el-tag>
          {{ scope.row.backNo}}
        </template>
      </el-table-column>
      <el-table-column prop="inboundNo" header-align="center" align="center" label="入库单号" width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-tag type="success" size="mini" @click="copyText(scope.row.inboundNo)" style="cursor: pointer;">
            复制
          </el-tag>
          {{scope.row.inboundNo}}
        </template>
      </el-table-column>
      <!-- <el-table-column prop="inboundType" header-align="center" align="center" label="入库类型">
        <template slot-scope="scope">
          <el-input size="mini" v-model="scope.row.inboundType" v-if="showInput == `inboundType${scope.row.inboundId}`"
            @blur='blurInput(scope.row, "inboundType", scope.row.inboundType)' v-focus>
          </el-input>
          <span v-else>{{scope.row.inboundType}}</span>
        </template>
      </el-table-column> -->
      <el-table-column prop="supplierName" header-align="center" align="center" label="供应商名称" width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-select size="mini" @focus="getSuppliers()" @click="getSuppliers()" @change='blurInput(scope.row, "supplierName", scope.row.supplierName)' v-model="scope.row.supplierName" clearable
            v-if="showInput == `supplierName${scope.row.backId}`"
            placeholder="请选择">
            <el-option v-for="item in suppliers" :key="item.supplierId" :label="item.supplierName" :value="item.supplierName">
            </el-option>
          </el-select>
          <span v-else class="active-input">{{scope.row.supplierName}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="inboundDate" header-align="center" align="center" label="入库日期" width="120">
      </el-table-column>
      <el-table-column prop="totalFee" header-align="center" align="center" label="总金额" width="120">
      </el-table-column>
      <el-table-column prop="headQuarterDate" header-align="center" align="center" label="总部日期" width="120">
      </el-table-column>
      <el-table-column prop="headQuarterNo" header-align="center" align="center" label="总部单号" width="150" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="backUser" header-align="center" align="center" label="退货人员" width="120">
        <template slot-scope="scope">
          <el-select size="mini" @focus="getUsers()" @change='blurInput(scope.row, "backUser", scope.row.backUser)' v-model="scope.row.backUser" clearable
            v-if="showInput == `backUser${scope.row.backId}`"
            placeholder="请选择">
            <el-option v-for="item in users" :key="item.userId" :label="item.username" :value="item.username">
            </el-option>
          </el-select>
          <span v-else class="active-input">{{scope.row.backUser}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="auditUser" header-align="center" align="center" label="审核人" width="120">
        <template slot-scope="scope">
          <el-select size="mini" @focus="getUsers()" @change='blurInput(scope.row, "auditUser", scope.row.auditUser)' v-model="scope.row.auditUser" clearable
            v-if="showInput == `auditUser${scope.row.backId}`"
            placeholder="请选择">
            <el-option v-for="item in users" :key="item.userId" :label="item.username" :value="item.username">
            </el-option>
          </el-select>
          <span v-else class="active-input">{{scope.row.auditUser}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="auditStatus" header-align="center" align="center" label="审核状态">
        <template slot-scope="scope">
          <el-tag type="success" size="mini" v-if="scope.row.auditStatus == 1">审核通过</el-tag>
          <el-tag type="danger" size="mini" v-else-if="scope.row.auditStatus == -1">审核不通过</el-tag>
          <el-tag type="info" size="mini" v-else>未审核</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="auditNote" header-align="center" align="center" label="审核说明" width="140">
      </el-table-column>
      <el-table-column prop="storeName" header-align="center" align="center" label="门店名称" v-if="hasRole('role:sys:super:admin')">
      </el-table-column>
      <el-table-column prop="storeCode" header-align="center" align="center" label="门店编码" v-if="hasRole('role:sys:super:admin')">
      </el-table-column>
      <el-table-column prop="updateTime" header-align="center" align="center" label="修改时间">
      </el-table-column>
      <el-table-column prop="updateUsername" header-align="center" align="center" label="修改人">
      </el-table-column>
      <el-table-column prop="remark" header-align="center" align="center" label="备注">
        <template slot-scope="scope">
          <span v-html="scope.row.remark"></span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="150" label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="text" v-if="isAuth('purchase:purchasesbackorder:save')"
            @click="saveHandle(scope.row)">保存</el-button>
          <el-button size="mini" type="text" v-if="isAuth('purchase:purchasesbackorder:update')"
            @click="addOrUpdateHandle(scope.row.backId)">修改</el-button>
          <el-button size="mini" type="text" v-if="isAuth('purchase:purchasesbackorder:delete')"
            @click="deleteHandle(scope.row.backId)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

<!-- 字表 -->
    <el-table :data="itemDataList" size="mini" v-loading="dataListLoading"  style="width: 100%;"
      @cell-click="itemTableDbEdit" @cell-dblclick="itemTableDbEdit" height="250"
      :header-cell-style="{ background: '#fcfcfc', color: '#606266', height:'36px'}" class="item-table" >
      <el-table-column prop="productCode" header-align="center" align="center" label="产品编码">
      </el-table-column>
      <el-table-column prop="productName" header-align="center" align="center" width="130" show-overflow-tooltip label="产品名称">
      </el-table-column>
      <el-table-column prop="produceDate" header-align="center" align="center" label="生产日期" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="expiryDate" header-align="center" align="center" label="有效期" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="purchaseCount" header-align="center" align="center" label="采购数量">
      </el-table-column>
      <el-table-column prop="backCount" header-align="center" align="center" label="退货数量">
        <template slot-scope="scope">
          <el-input size="mini" v-model="scope.row.backCount" v-if="showItemInput == `backCount${scope.row.backDetailId}`"
            @blur='blurItemInput(scope.row, "backCount", scope.row.backCount)' v-focus>
          </el-input>
          <span v-else class="active-input">{{scope.row.backCount}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="purchasePrice" header-align="center" align="center" label="采购价格">
      </el-table-column>
      <el-table-column prop="purchaseFee" header-align="center" align="center" label="采购金额">
      </el-table-column>
      <el-table-column prop="batchNo" header-align="center" align="center" label="批号" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="lastPurchasePrice" header-align="center" align="center" label="上次进价">
      </el-table-column>
      <el-table-column prop="retailPrice" header-align="center" align="center" label="原零售价">
      </el-table-column>
      <el-table-column prop="newRetailPrice" header-align="center" align="center" label="零售价">
      </el-table-column>
      <el-table-column prop="memberPrice" header-align="center" align="center" label="原会员价">
      </el-table-column>
      <el-table-column prop="newMemberPrice" header-align="center" align="center" label="会员价">
      </el-table-column>
      <el-table-column prop="barCode" header-align="center" align="center" label="条形码" width="130" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="genericName" header-align="center" align="center" label="通用名称" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="standard" header-align="center" align="center" label="规格" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="unit" header-align="center" align="center" label="单位">
      </el-table-column>
      <el-table-column prop="producingArea" header-align="center" align="center" label="产地" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="produceFactory" header-align="center" align="center" label="生产单位" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="approvalNo" header-align="center" align="center" label="批准文号" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="dosageForm" header-align="center" align="center" label="剂型" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="keyNo" header-align="center" align="center" label="f4流水号">
      </el-table-column>

      <el-table-column prop="updateTime" header-align="center" align="center" label="修改时间" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="updateUsername" header-align="center" align="center" label="修改人">
        <template slot-scope="scope">
        </template>
      </el-table-column>
      <el-table-column prop="remark" header-align="center" align="center" label="备注">
        <template slot-scope="scope">
          <span v-html="scope.row.remark"></span>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <!-- 审核 -->
    <dialog-audit v-if="auditVisible" ref="dialogAudit"></dialog-audit>
  </div>
</template>

<script>
  import AddOrUpdate from './purchasesbackorder-add-or-update'
  import {downLoadFile  } from '@/utils/myUtil.js'
  import {Loading} from "element-ui"
  import DialogAudit from '@/views/components/dialog-audit'
  export default {
    components: {
      AddOrUpdate,
      DialogAudit
    },
    data() {
      return {
        dataForm: {
          queryDates:[],
          isAudit: undefined,
          key: '',
          queryField: '',
          itemKey: '',
          queryItemField: '',
        },
        suppliers:[],
        users: [],
        queryFields: [],
        queryItemFields: [],
        dataList: [],
        itemDataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,
        auditVisible: false,
        showInput: "",
        oldData: {},
        currentData: {},
        showItemInput: "",
        oldItemData: {},
        currentItemData: {},
        //导入
        upload: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "导入药品数据",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          // updateSupport: 0,
          // 设置上传的请求头部
          // 上传的地址
          url: `${window.SITE_CONFIG.baseUrl}/purchase/purchasesbackorder/importData`
        },
        //上传的文件
        excelList: [],
      }
    },
    activated() {
      this.getDataList()
      this.initQueryParams()
    },
    methods: {
      // 获取数据列表
      async getDataList() {
        this.dataListLoading = true
        let newDataForm = _.cloneDeep(this.dataForm)
        let queryDates = newDataForm.queryDates || [];
        newDataForm.queryDates = queryDates.join(",")
        const res = await this.$http({
          url: `/purchase/purchasesbackorder/page`,
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'dataForm': newDataForm
          })
        })
        let data = res.data
        if (data && data.code === 0) {
          this.dataList = data.page.list
          this.totalPage = data.page.totalCount
          this.dataList.forEach(item => {
            item.status = item.status == 1 ? true : false
          })
          if (this.dataList.length > 0) {
            this.getItemDataList(this.dataList[0].backId)
          }else{
            this.itemDataList = []
          }
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      },
      async getItemDataList(backId) {
        console.log("backId===", backId)
        const res = await this.$http({
          url: `/purchase/purchasesbackorderdetail/listByBackId`,
          method: 'get',
          params: this.$http.adornParams({
            backId
          })
        })
        let data = res.data
        if (data && data.code === 0) {
          this.itemDataList = data.list
        } else {
          this.itemDataList = []
        }
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle(val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle(id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle(id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.backId
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          const res = await this.$http({
            url: `/purchase/purchasesbackorder/delete`,
            method: 'delete',
            data: this.$http.adornData(ids, false)
          })
          let data = res.data
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList()
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      },
      resetForm() {
        this.$nextTick(() => {
          this.dataForm = this.$options.data().dataForm
          this.getDataList()
        })
      },
      async saveHandle(row) {
        console.log("saveHandle row===", row)
        row.status = row.status ? 1 : 0
        const res = await this.$http({
          url: `/purchase/purchasesbackorder/update`,
          method: 'post',
          data: this.$http.adornData(row)
        });
        let data = res.data
        if (data && data.code !== 0) {
          row.status = !row.status;
          return this.$message.error('修改失败!');
        }
        this.$message.success('更新成功！');
        this.getDataList();
      },
      // 当input失去光标后进行的操作
      async blurInput(row, name, value) {
        // 判断数据是否有所改变，如果数据有改变则调用修改接口
        if (this.oldData[name] != value) {
          row[name] = value
          if (value === true) {
            row[name] = 1
          } else if (value === false) {
            row[name] = 0
          }
        }
        this.showInput = ""
        this.currentData = row
        if(name === 'supplierName'){
          this.setSuppliers(row)
        }
      },
      tableDbEdit(row, column, event) {
        this.showInput = column.property + row.backId;
        this.oldData[column.property] = row[column.property];
      },
      async blurItemInput(row, name, value) {
        // 判断数据是否有所改变，如果数据有改变则调用修改接口
        if (this.oldItemData[name] != value) {
          row[name] = value
          if (value === true) {
            row[name] = 1
          } else if (value === false) {
            row[name] = 0
          }
        }
        this.showItemInput = ""
        this.currentItemData = row
        this.saveItemHandle(row)
      },
      itemTableDbEdit(row, column, event){
        this.showItemInput = column.property + row.backDetailId;
        this.oldItemData[column.property] = row[column.property];
      },
      async saveItemHandle(row) {
        this.$confirm(`确定对货号[${row.productCode}]进行更新操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
            row.status = row.status ? 1 : 0
            const res = await this.$http({
              url: `/purchase/purchasesbackorderdetail/update`,
              method: 'post',
              data: this.$http.adornData(row)
            });
            let data = res.data
            if (data && data.code !== 0) {
              row.status = !row.status;
              return this.$message.error('修改失败!');
            }
            this.$message.success('更新成功！');
            this.getDataList();
         })
      },
      async exportData() {
        const res = await this.$http({
          url: `/purchase/purchasesbackorder/exportData`,
          method: 'get',
          responseType: 'blob',
          params: this.$http.adornParams()
        });
        downLoadFile(res)
      },
      beforeUpload(file) {
        //截取文件后缀名
        const fileName = file.name.substring(file.name.lastIndexOf('.'));
        if (fileName.toLowerCase() != '.xls' && fileName.toLowerCase() != '.xlsx') {
          this.$message.error('文件必须为.xls或xlsx类型')
          this.fileList = []
          return false
        };
        //读取文件大小
        var fileSize = file.size;
        if (fileSize > 3249576) {
          this.uploadShowDialog = false;
          this.$message({
            type: 'error',
            showClose: true,
            duration: 3000,
            message: '文件不能大于3M!'
          });
          return false;
        }
      },
      // excel表上传
      handleUploadChange(file, fileList) {
        if (fileList.length > 0) {
          // 这一步，是展示最后一次选择的文件
          this.fileList = [fileList[fileList.length - 1]];
        }
      },
      //导入按钮
      handleImport() {
        this.upload.open = true;
      },
      //导入提交
      async submitFileForm() {
        if (this.excelList.length === 0) {
          this.$message.warning("请选择文件");
          return;
        }
        if (this.excelList.length > 1) {
          this.$message.warning("每次只能提交一个文件");
          return;
        }
        let formData = new FormData();
        this.excelList.forEach((item) => {
          formData.append("file", item.raw);
        });
        let loadingInstance = Loading.service({
          lock: true, //lock的修改符--默认是false
          text: "导入中", //显示在加载图标下方的加载文案
          spinner: "el-icon-loading", //自定义加载图标类名
          background: "rgba(0, 0, 0, 0.7)", //遮罩层颜色
          target: document.querySelector("#futureTransferDialog"), //loadin覆盖的dom元素节点
        });
        const res = await this.$http({
          url: this.upload.url,
          method: 'post',
          data: formData
        })
        let data = res.data
        if (data && data.code === 0) {
          loadingInstance.close();
          this.$message({
            type: "success",
            message: "导入成功!",
          });
          this.getDataList();
        }
        this.excelList = [];
        this.upload.open = false;
        loadingInstance.close();
        this.dataListLoading = false
      },
      //下载导入模板
      downloadImportTemplate() {
        window.location.href = "http://file.asdzy.com/upload/files/film/品牌模板.xlsx"
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {
        this.excelList = fileList;
      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
      },
      onChangeDr(file, fileList) {
        this.excelList = fileList;
      },
      onRemoveDr(file, fileList) {
        this.excelList = fileList;
      },
      cancelFileForm() {
        this.upload.open = false
        this.excelList = [];
      },
      showAuditDialog(){
        if(this.dataListSelections.length === 0){
          this.$message.warning("请选择要审核的单据！")
          return;
        }
        for(let item of this.dataListSelections){
          if(item.auditStatus === 1){
            this.$message.warning("请选择未审核的单据！")
            return;
          }
        }
        this.auditVisible = true
        this.$nextTick(() => {
          this.$refs.dialogAudit.init("采购入库")
        })
      },
      async audit(option){
        let ids = this.dataListSelections.map(item => {
          return item.backId
        })
        option.ids = ids.join(",")
        const res = await this.$http({
          url:`/purchase/purchasesbackorder/audit`,
          method: 'post',
          data: this.$http.adornData(option, false)
        })
        let data = res.data
        if (data && data.code === 0) {
            this.$message.success("审核成功！")
            this.auditVisible = false
            this.getDataList()
        } else {
            this.$message.error(data.msg)
        }
      },
      async getUsers() {
        const res = await this.$http({
          url: `/sys/user/listUsers`,
          method: 'get',
          params: this.$http.adornParams()
        })
        let data = res.data
        if (data && data.code === 0) {
          this.users = data.data
        }
      },
      async getDicts(type) {
        const res = await this.$http({
          url: '/base/basedict/getDict',
          method: 'get',
          params: this.$http.adornParams({
            'code': type
          })
        })
        let data = res.data
        if (data && data.code === 0) {
          if(type === 'TEMPERATURE_CONTROL'){
            this.temperatureControls = data.data
          }else if(type === 'TRANSPORT_TOOL'){
            this.transportTools = data.data
          }else if(type === 'DELIVERY_TEMPERATURE'){
            this.deliveryTemperatures = data.data
          }else if(type === 'TRANSPORT_METHOD'){
            this.transportMethods = data.data
          }
        }
      },
      copyClipboard(data, txt = "") {
        let url = data;
        let oInput = document.createElement("input");
        oInput.value = url;
        document.body.appendChild(oInput);
        oInput.select(); // 选择对象
        document.execCommand("Copy"); // 执行浏览器复制命令
        this.$message({
          title: "提示",
          message: `${txt} ${data} 复制到剪切板成功`,
          type: "success",
          duration: 1000
        });
        oInput.remove();
      },
      async getSuppliers() {
        const res = await this.$http({
          url: `/product/supplier/getSupplies`,
          method: 'get',
          params: this.$http.adornParams()
        })
        let data = res.data
        if (data && data.code === 0) {
          this.suppliers = data.data
        }
      },
      setSuppliers(row) {
        for (let index in this.suppliers) {
          let item = this.suppliers[index]
          if (row.supplierName === item.supplierName) {
              row.supplierId = item.supplierId
              return
          }
        }
      },
      initQueryParams() {
          let queryFields = [{
            value: 'purchase_order_no',
            label: '采购编码'
          }, {
            value: 'head_quarter_no',
            label: '总部出货单号'
          }, {
            value: 'supplier_name',
            label: '供应商'
          }, {
            value: 'purchase_user',
            label: '采购人'
          }, {
            value: 'audit_username',
            label: '审核人'
          }]

          let queryItemFields = [{
            value: 'product_code',
            label: '编码'
          }, {
            value: 'bar_code',
            label: '条形码'
          }, {
            value: 'product_name',
            label: '产品名称'
          }, {
            label: '通用名'
          }, {
            value: 'producing_area',
            label: '产地'
          }, {
            value: 'produce_factory',
            label: '厂家'
          }, {
            value: 'dosage_form',
            label: '剂型'
          }, {
            value: 'standard',
            label: '规格'
          }, {
            value: 'approval_no',
            label: '批准文号'
          }]
          this.queryFields = queryFields;
          this.queryItemFields = queryItemFields;
        }
    },
    directives: {
      // 通过自定义指令实现的表单自动获得光标的操作
      focus: {
        inserted: function(el) {
          if (el.tagName.toLocaleLowerCase() == "input") {
            el.focus()
          } else {
            if (el.getElementsByTagName("input")) {
              el.getElementsByTagName("input")[0].focus()
            }
          }
          el.focus()
        }
      },
      focusTextarea: {
        inserted: function(el) {
          if (el.tagName.toLocaleLowerCase() == "textarea") {
            el.focus()
          } else {
            if (el.getElementsByTagName("textarea")) {
              el.getElementsByTagName("textarea")[0].focus()
            }
          }
          el.focus()
        }
      }
    },
  }
</script>
<style lang="less" scoped>
  .item-table {
    margin-top: 35px;
  }

  .el-select {
    max-width: 100px;
  }

  .el-input {
    margin: 0px;
  }
</style>
